/*
 * This file is part of LazyCipher. LazyCipher is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version. LazyCipher is distributed in
 * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details. You should have received a
 * copy of the GNU General Public License along with LazyCipher. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package org.lazycoder.Crypto;

import java.util.Iterator;
import java.util.Vector;

import org.lazycoder.Crypto.Letter;

/**
 * A cipher message. This can be either the plain text or the enciphered text,
 * it's not possible to know which.
 * 
 * @author Matthew Bayliss
 */
public class Message {
	/** A vector containing all the letters in the message */
	private final Vector<Letter>	message	= new Vector<Letter>();

	/**
	 * Constructor that will set the message contained here.
	 * 
	 * @param message
	 *            the message.
	 */
	public Message(String message) {
		setMessage(message);
	}

	/**
	 * Set the message
	 * 
	 * @param message
	 *            the plain text.
	 */
	public void setMessage(String message) {
		this.message.clear();
		for (int i = 0; i < message.length(); i++) {
			char c = message.charAt(i);
			this.message.add(Letter.createLatinLetter(c));
		}
	}

	public Letter getLetter(int id) {
		id %= message.size();
		return message.get(id);
	}

	public Iterator<Letter> getIterator() {
		return message.iterator();
	}

	@Override
	public String toString() {
		String s = "";
		Iterator<Letter> itr = message.iterator();
		while (itr.hasNext()) {
			String l = itr.next().toString();
			s = s.concat(l);
		}
		return s;
	}

}
